<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // function runP1() {
        //     // Promise 实例化
        //     const p1 = new Promise(r => console.log('立即打印'));
        //     return p1;
        // }
        // 异步  sync 同步
        function runAsync(x) {
            const p = new Promise(resolve => setTimeout(() => resolve(x,console.log(x)),1000));
            return p;
        }
        // runAsync(1)
        //     .then(data => {
        //         console.log(data);
        //     });
        // js 单线程
        // Promise.all 接受并发
        Promise.all([runAsync(1),runAsync(2),runAsync(3)])
            // 要等到所有的 Promise 都执行完 -> fullfiled 
            // 保持 Promise 顺序来返回结果
            .then(res => console.log(res));
    </script>
</body>
</html>